<template>
	<view class="t-login">
		<view class="t-b">{{title}}</view>
		<view class="nickname-wapper">
			<image class="icon" src="@/static/nicknamee.png"></image>
			<input type="nickname" v-model="nickname" class="nickname" @blur="changeInput" placeholder="请输入昵称" />
		</view>
		<button class="login" form-type="submit" @tap="login">一键登录</button>
		<!-- <form class="cl">
			<button class="avatar-wrapper" open-type="chooseAvatar" @chooseavatar="onChooseAvatar">
				<image class="avatar" src="../../static/avatar.png"></image>
			</button>
			<view class="t-a">
				<image src="@/static/nicknamee.png"></image>
				<input type="nickname" v-model="nickname" class="weui-input" @blur="changeInput" placeholder="请输入昵称" />
			</view>
			<button form-type="submit" @tap="login">一键登录</button>
		</form> -->
		<!-- <view class="t-f">登录即同意<text>用户协议</text></view>
		<view class="t-e cl">
			<view class="t-g">
				<image src="@/static/wx.png"></image>
				<view>微信</view>
			</view>
			<view class="t-g">
				<image src="@/static/qq.png"></image>
				<view>QQ</view>
			</view>
		</view> -->
		<!-- <update v-if="Object.keys(update).length>0" :updateType="update.updateType" :updateTitle="update.updateTitle"
		 :updateDes="update.updateDes" :updateUrl="update.updateUrl" :isForcedUpdate="update.isForcedUpdate" :isUpdateApp="update.isUpdateApp"></update> -->
	</view>
</template>
<script>
	import {
		mapGetters,
		mapActions
	} from "vuex";
	import {
		USER_TOKEN
	} from '@/common/util/constants.js';
	import configService from '@/common/service/config.service.js';
	export default {
		components: {},
		data() {
			return {
				username: '',
				password: '',
				title: '欢迎登录账号',
				nickname: '',
			}
		},
		computed: {
			...mapGetters(['token'])
		},
		methods: {
			...mapActions(['loginAction', 'userInfoAction', 'isLoginAction', 'setPermission']),
			login() {
				console.log('username------>', this.username);
				if (this.username == '') {
					uni.showToast({
						title: '请输入用户名'
					});
					return;
				}
				let that = this;
				uni.login({
					provider: 'weixin',
					success(res) {
						let userinfo = {
							params: {
								username: that.username,
								password: res.code
							}
						};
						that.loginAction(userinfo).then(res => {
							if (res.data.code == 200) {
								that.isLoginAction(true);
								uni.showToast({
									title: '登录成功!',
									icon: 'none'
								})
								//3秒后跳转到首页
								setTimeout((res) => {
									console.log('log1 login success---->!');
									that.$Router.replaceAll({
										name: 'homeIndex'
									});
								}, 1500)

							}
						}).catch(err => {
							console.log('err----->', err);
						})
					}
				})
			},
			changeInput(e) {
				this.username = e.detail.value;
				console.log('username------>',this.username);
			},
		}
	}
</script>
<style lang="scss" scoped>
	.t-login {
		width: 600rpx;
		margin: 0 auto;
		font-size: 28rpx;
		color: #000
	}

	.t-login .t-b {
		text-align: center;
		font-size: 46rpx;
		color: #000;
		padding: 100rpx 0;
	}

	.avatar-wrapper {
		width: 100px;
		height: 70px;
		border-radius: 50%;

		.avatar {
			width: 100%;
			height: 100%;
			border-radius: 50%;
		}
	}

	.nickname-wapper {
		display: flex;

		.icon {
			flex: 0 0 25px;
			height: 25px;
		}

		.nickname {}
	}

	.login {
		margin-top: 25px;
		color: white;
		background-color: #000;
		border-radius: 15px;
	}
</style>